function [] = fp_adder_tb()
    % 0.3+1.0=1.3
    A = [0   0 1 1 1 1 1 0 1   0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0]; % +0.3
    B = [0   0 1 1 1 1 1 1 1   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +1.0
    E = [0   0 1 1 1 1 1 1 1   0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0]; % +1.3
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
    
    % 1.0-0.3=0.7
    A = [0   0 1 1 1 1 1 1 1   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +1.0
    B = [1   0 1 1 1 1 1 0 1   0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0]; % -0.3
    E = [0   0 1 1 1 1 1 1 0   0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1]; % +0.7
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
    
    % -0.3+1.0=0.7
    A = [1   0 1 1 1 1 1 0 1   0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0]; % -0.3
    B = [0   0 1 1 1 1 1 1 1   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +1.0
    E = [0   0 1 1 1 1 1 1 0   0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1]; % +0.7
    S = fp_adder(A,B,0);
    assert(A,B,S,E);

    % 0.3-1.0=0.7
    A = [0   0 1 1 1 1 1 0 1   0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0]; % +0.3
    B = [0   0 1 1 1 1 1 1 1   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +1.0
    E = [0   0 1 1 1 1 1 1 0   0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1]; % +0.7
    S = fp_adder(A,B,1);
    assert(A,B,S,E);
    
    % -1.0+0.3=-0.7
    A = [1   0 1 1 1 1 1 1 1   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +1.0
    B = [0   0 1 1 1 1 1 0 1   0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0]; % +0.3
    E = [1   0 1 1 1 1 1 1 0   0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1]; % -0.7
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
    
    % 0.001+0.05=0.051
    A = [0   0 1 1 1 0 1 0 1   0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1]; % +0.001
    B = [0   0 1 1 1 1 0 1 0   1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1]; % +0.05
    E = [0   0 1 1 1 1 0 1 0   1 0 1 0 0 0 0 1 1 1 0 0 1 0 1 0 1 1 0 0 0 0 0]; % +0.051
    S = fp_adder(A,B,0);
    assert(A,B,S,E);

    % 1.0+2.0=3.0
    A = [0   0 1 1 1 1 1 1 1   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +1.0
    B = [0   1 0 0 0 0 0 0 0   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +2.0
    E = [0   1 0 0 0 0 0 0 0   1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +3.0
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
    
    % 14.0+14.0=28.0
    A = [0   1 0 0 0 0 0 1 0   1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +14.0
    B = [0   1 0 0 0 0 0 1 0   1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +14.0
    E = [0   1 0 0 0 0 0 1 1   1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % +28.0
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
    
    % 12.1+6.3=18.400002
    A = [0   1 0 0 0 0 0 1 0   1 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0]; % +12.1
    B = [0   1 0 0 0 0 0 0 1   1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0]; % +6.3
    E = [0   1 0 0 0 0 0 1 1   0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1]; % +18.400002
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
    
    % 123456789 + 987654321 = 1.1111e+009
    A = [0   1 0 0 1 1 0 0 1   1 1 0 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 1]; % +123456789
    B = [0   1 0 0 1 1 1 0 0   1 1 0 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 1]; % +987654321
    E = [0   1 0 0 1 1 1 0 1   0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 1]; % +1.1111e+009
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
    
   % 0.123456789 + 0.987654321 = 1.1111112
    A = [0   0 1 1 1 1 0 1 1   1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 0 1 0 1 0]; % +0.123456789
    B = [0   0 1 1 1 1 1 1 0   1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 0 1 0 1 0]; % +0.987654321
    E = [0   0 1 1 1 1 1 1 1   0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1]; % +1.1111112
    S = fp_adder(A,B,0);
    assert(A,B,S,E);
end

function assert(A,B,S,E)
    A_dec = fp2dec(A);
    B_dec = fp2dec(B);
    S_dec = fp2dec(S);
    S_ = fp2dec(E);
    if S == E
        fprintf('\tYES: %.32f\t\t\t\t+\t\t%.32f\t\t=\t\t%.32f\n',A_dec,B_dec,S_dec);
    else
        fprintf('\tNO : %.45f+%.45f=%.45f, correct is: %.45f\n\t%s should be\n\t%s\n',A_dec,B_dec,S_dec,S_,mat2str(S),mat2str(E));
    end
end
